@echo off
setlocal

echo Manual Copy Commands for PPH System
echo ====================================
echo.

set SOURCE_ROOT=D:\OneDrive\Desktop\新PPH项目
set TARGET_ROOT=D:\OneDrive\Desktop\新PPH项目\PPH-Production-Deploy\app

echo Source Root: %SOURCE_ROOT%
echo Target Root: %TARGET_ROOT%
echo.

if not exist "%SOURCE_ROOT%" (
    echo ERROR: Source directory not found!
    echo Please check the path: %SOURCE_ROOT%
    pause
    exit /b 1
)

echo Creating target directories...
md "%TARGET_ROOT%" 2>nul
md "%TARGET_ROOT%\backend" 2>nul
md "%TARGET_ROOT%\frontend" 2>nul
md "%TARGET_ROOT%\backend\data" 2>nul
md "%TARGET_ROOT%\logs" 2>nul
echo Directories created.
echo.

echo Copying backend files...
xcopy "%SOURCE_ROOT%\backend\*.*" "%TARGET_ROOT%\backend\" /E /I /Y /EXCLUDE:exclude.txt
echo Backend files copied.
echo.

echo Copying frontend files...
xcopy "%SOURCE_ROOT%\frontend\*.*" "%TARGET_ROOT%\frontend\" /E /I /Y /EXCLUDE:exclude.txt
echo Frontend files copied.
echo.

echo Copying database file...
if exist "%SOURCE_ROOT%\backend\data\pph.sqlite" (
    copy "%SOURCE_ROOT%\backend\data\pph.sqlite" "%TARGET_ROOT%\backend\data\" /Y
    echo Database file copied.
) else (
    echo WARNING: Database file not found.
)
echo.

echo Copying additional files...
if exist "%SOURCE_ROOT%\check-staff-fields.cjs" (
    copy "%SOURCE_ROOT%\check-staff-fields.cjs" "%TARGET_ROOT%\" /Y
    echo check-staff-fields.cjs copied.
)

if exist "%SOURCE_ROOT%\legacyDb.db" (
    copy "%SOURCE_ROOT%\legacyDb.db" "%TARGET_ROOT%\" /Y
    echo legacyDb.db copied.
)

if exist "%SOURCE_ROOT%\package.json" (
    copy "%SOURCE_ROOT%\package.json" "%TARGET_ROOT%\" /Y
    echo package.json copied.
)
echo.

echo Verifying key files...
if exist "%TARGET_ROOT%\backend\server-simple.cjs" (
    echo [OK] server-simple.cjs found
) else (
    echo [ERROR] server-simple.cjs missing
)

if exist "%TARGET_ROOT%\backend\package.json" (
    echo [OK] backend package.json found
) else (
    echo [ERROR] backend package.json missing
)

if exist "%TARGET_ROOT%\frontend\package.json" (
    echo [OK] frontend package.json found
) else (
    echo [ERROR] frontend package.json missing
)

if exist "%TARGET_ROOT%\frontend\index.html" (
    echo [OK] frontend index.html found
) else (
    echo [ERROR] frontend index.html missing
)

echo.
echo Copy process completed!
echo.
echo Next steps:
echo 1. Run: install-dependencies.bat
echo 2. Run: deploy-cmd.bat
echo.
pause
